package ${package.Controller};

import org.springframework.web.bind.annotation.RequestMapping;
import ${package.Service}.${table.serviceName};
import ${package.Entity}.${entity};
import com.robot.common.core.domain.Query;
import com.robot.common.core.tool.PageTransform;
import com.robot.common.core.tool.R;
import com.robot.common.core.tool.WrapperTransform;
import com.robot.utils.ListUtil;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>

/**
 * <p>
 * ${table.comment!} 前端控制器
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
@AllArgsConstructor
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@RequestMapping("<#if package.ModuleName?? && package.ModuleName != "">/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} {
</#if>

    private ${table.serviceName} ${entity?uncap_first}Service;

    /**
     * 分页查询
     * @param query 分页信息，current-当前页，size-每页条数
     * @param ${entity?uncap_first} 实体类
     * @return
     */
    @GetMapping("/page")
    public R page(Query query,${entity} ${entity?uncap_first}){
        return R.data(${entity?uncap_first}Service.page(PageTransform.getPage(query), WrapperTransform.getDefuatWrapper(${entity?uncap_first})));
    }

    /**
     * 自定义分页查询
     * @param query 分页信息，current-当前页，size-每页条数
     * @param ${entity?uncap_first} 实体类
     * @return
     */
    @GetMapping("/getPage")
    public R getPage(Query query,${entity} ${entity?uncap_first}){
        return R.data(${entity?uncap_first}Service.getPage(PageTransform.getPage(query),${entity?uncap_first}));
    }

    /**
     * 查询列表
     * @param ${entity?uncap_first} 实体类
     * @return
     */
    @GetMapping("/list")
    public R list(${entity} ${entity?uncap_first}){
        return R.data(${entity?uncap_first}Service.list(WrapperTransform.getDefuatWrapper(${entity?uncap_first})));
    }

    /**
     * 查询单条信息
     * @param sysUser 实体类，请传唯一值
     * @return
     */
    @GetMapping("/detail")
    public R detail(${entity} ${entity?uncap_first}){
        return R.data(${entity?uncap_first}Service.getOne(WrapperTransform.getDefuatWrapper(${entity?uncap_first})));
    }

    /**
     * 保存信息
     * @param sysUser 实体类
     * @return
     */
    @PostMapping("/save")
    public R save(@RequestBody ${entity} ${entity?uncap_first}){
        return R.status(${entity?uncap_first}Service.save(${entity?uncap_first}));
    }

    /**
     * 更新信息
     * @param ${entity?uncap_first}
     * @return
     */
    @PutMapping
    public R update(@RequestBody ${entity} ${entity?uncap_first}){
        return R.status(${entity?uncap_first}Service.updateById(${entity?uncap_first}));
    }

    /**
     * 删除信息
     * @param ids
     * @return
     */
    @DeleteMapping("/{ids}")
    public R delete(@PathVariable String ids){
        return R.status(${entity?uncap_first}Service.removeByIds(ListUtil.toLongList(ids,",")));
    }
}
</#if>
